
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/02/2012 22:47:07
-- Generated from EDMX file: E:\maylove\VideoTag\VideoTag\LAB\Tager.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Tager];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[t_bag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_bag];
GO
IF OBJECT_ID(N'[dbo].[t_finder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_finder];
GO
IF OBJECT_ID(N'[dbo].[t_finderTag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_finderTag];
GO
IF OBJECT_ID(N'[dbo].[t_status]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_status];
GO
IF OBJECT_ID(N'[dbo].[t_subscribe]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_subscribe];
GO
IF OBJECT_ID(N'[dbo].[t_syno]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_syno];
GO
IF OBJECT_ID(N'[dbo].[t_tag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_tag];
GO
IF OBJECT_ID(N'[dbo].[t_user]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_user];
GO
IF OBJECT_ID(N'[dbo].[t_video]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_video];
GO
IF OBJECT_ID(N'[dbo].[t_videoTag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[t_videoTag];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 't_bag'
CREATE TABLE [dbo].[t_bag] (
    [id] int IDENTITY(1,1) NOT NULL,
    [name] varchar(50)  NOT NULL,
    [status] int  NOT NULL,
    [editor] varchar(50)  NOT NULL,
    [dt] datetime  NOT NULL
);
GO

-- Creating table 't_finder'
CREATE TABLE [dbo].[t_finder] (
    [id] int IDENTITY(1,1) NOT NULL,
    [name] varchar(50)  NULL,
    [owner] varchar(50)  NULL,
    [rank] int  NULL
);
GO

-- Creating table 't_finderTag'
CREATE TABLE [dbo].[t_finderTag] (
    [id] int IDENTITY(1,1) NOT NULL,
    [finderId] int  NOT NULL,
    [tagId] int  NOT NULL
);
GO

-- Creating table 't_status'
CREATE TABLE [dbo].[t_status] (
    [id] int IDENTITY(1,1) NOT NULL,
    [number] int  NOT NULL,
    [name] varchar(50)  NOT NULL
);
GO

-- Creating table 't_subscribe'
CREATE TABLE [dbo].[t_subscribe] (
    [id] int IDENTITY(1,1) NOT NULL,
    [interval] int  NOT NULL,
    [finderId] int  NOT NULL
);
GO

-- Creating table 't_tag'
CREATE TABLE [dbo].[t_tag] (
    [id] int IDENTITY(1,1) NOT NULL,
    [name] varchar(50)  NOT NULL,
    [status] int  NOT NULL,
    [bagId] int  NOT NULL,
    [editor] varchar(50)  NOT NULL,
    [dt] datetime  NOT NULL,
    [count] int  NOT NULL
);
GO

-- Creating table 't_video'
CREATE TABLE [dbo].[t_video] (
    [id] int IDENTITY(1,1) NOT NULL,
    [name] varchar(128)  NOT NULL,
    [dt] datetime  NOT NULL,
    [status] int  NOT NULL,
    [count] int  NOT NULL,
    [editor] varchar(50)  NOT NULL,
    [url] varchar(1024)  NOT NULL
);
GO

-- Creating table 't_videoTag'
CREATE TABLE [dbo].[t_videoTag] (
    [id] int IDENTITY(1,1) NOT NULL,
    [videoId] int  NOT NULL,
    [tagId] int  NOT NULL,
    [dt] datetime  NOT NULL
);
GO

-- Creating table 't_syno'
CREATE TABLE [dbo].[t_syno] (
    [id] int IDENTITY(1,1) NOT NULL,
    [tagId] int  NOT NULL,
    [name] varchar(50)  NOT NULL,
    [status] int  NOT NULL
);
GO

-- Creating table 't_user'
CREATE TABLE [dbo].[t_user] (
    [id] int IDENTITY(1,1) NOT NULL,
    [userName] nvarchar(20)  NOT NULL,
    [pwd] varchar(20)  NOT NULL,
    [dt] datetime  NOT NULL,
    [status] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [id] in table 't_bag'
ALTER TABLE [dbo].[t_bag]
ADD CONSTRAINT [PK_t_bag]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_finder'
ALTER TABLE [dbo].[t_finder]
ADD CONSTRAINT [PK_t_finder]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_finderTag'
ALTER TABLE [dbo].[t_finderTag]
ADD CONSTRAINT [PK_t_finderTag]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_status'
ALTER TABLE [dbo].[t_status]
ADD CONSTRAINT [PK_t_status]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_subscribe'
ALTER TABLE [dbo].[t_subscribe]
ADD CONSTRAINT [PK_t_subscribe]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_tag'
ALTER TABLE [dbo].[t_tag]
ADD CONSTRAINT [PK_t_tag]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_video'
ALTER TABLE [dbo].[t_video]
ADD CONSTRAINT [PK_t_video]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_videoTag'
ALTER TABLE [dbo].[t_videoTag]
ADD CONSTRAINT [PK_t_videoTag]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_syno'
ALTER TABLE [dbo].[t_syno]
ADD CONSTRAINT [PK_t_syno]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 't_user'
ALTER TABLE [dbo].[t_user]
ADD CONSTRAINT [PK_t_user]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------